# -*- coding: utf-8 -*-
# autor: Rui-6047, Pedro-11240
# data: 25 de Outubro de 2013
# obs: 1º Parte do Trabalho de LP

import csv

########################################################################
## Escrita em csv - Guarda o nº de inscritos por instituicao
########################################################################
def csv_PostedNumberPerInstitutions(allInstitutions, 
										postedNumberPerInstitutions):
	csv_file = open('csv_alunos_por_instituicao.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(allInstitutions):
		row = []
		row.append(str(item.encode('utf-8')))
		row.append(postedNumberPerInstitutions[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - Guarda o nº de vagas por instituicao
########################################################################
def csv_FreeNumberPerInstitutions(allInstitutions, 
									freeNumberPerInstitutions):
	csv_file = open('csv_vagas_por_instituicao.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(allInstitutions):
		row = []
		row.append(str(item.encode('utf-8')))
		row.append(freeNumberPerInstitutions[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - Guarda o nº de colocados por Distrito
########################################################################
def csv_postedNumberPerDistrict(distritos, postedNumberPerDistrict):
	csv_file = open('csv_alunos_por_distrito.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(distritos):
		row = []
		row.append(str(item[0].encode('utf-8')))
		row.append(postedNumberPerDistrict[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - Guarda o nº de vagas por Distrito
########################################################################
def csv_freeNumberPerDistrict(distritos, freeNumberPerDistrict):
	csv_file = open('csv_vagas_por_distrito.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(distritos):
		row = []
		row.append(str(item[0].encode('utf-8')))
		row.append(freeNumberPerDistrict[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - percentagem de alunos por instituicao
########################################################################
def csv_StudentPercent(allInstitutions, studentPercent):
	csv_file = open('csv_percetagem_por_instituicao.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(allInstitutions):
		row = []
		row.append(str(item.encode('utf-8')))
		row.append(studentPercent[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - perleminagem de alunos por Distrito
########################################################################
def csv_StudentPermil(distritos, studentPermil):
	csv_file = open('csv_perleminagem_por_distrito.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')

	for index, item in enumerate(distritos):
		row = []
		row.append(str(item[0].encode('utf-8')))
		row.append(studentPermil[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - todos os dados das instituicoes
########################################################################
def csv_global_info_institutions(allInstitutions, 
									postedNumberPerInstitutions, 
									freeNumberPerInstitutions, 
									studentPercent):
	csv_file = open('csv_info_instituicoes.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')
	
	row = []
	row.append('Nome da Instituição')
	row.append('Nº de alunos Colocados')
	row.append('Nº de Vagas')
	row.append('Percentagem por Instituição')
	file_writer.writerow(row)
	
	for index, item in enumerate(allInstitutions):
		row = []
		row.append(str(item.encode('utf-8')))
		row.append(postedNumberPerInstitutions[index])
		row.append(freeNumberPerInstitutions[index])
		row.append(studentPercent[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass

########################################################################
## Escrita em csv - todos os dados dos distritos
########################################################################	
def csv_global_info_district(distritos, 
							postedNumberPerDistrict, 
							freeNumberPerDistrict, 
							studentPermil):
	csv_file = open('csv_info_distritos.csv', 'wb')
	file_writer = csv.writer(csv_file, delimiter = ';')
	
	row = []
	row.append('Nome do Distrito')
	row.append('Nº de alunos Colocados')
	row.append('Nº de Vagas')
	row.append('Perleminagem por Distrito')
	file_writer.writerow(row)
	
	for index, item in enumerate(distritos):
		row = []
		row.append(str(item[0].encode('utf-8')))
		row.append(postedNumberPerDistrict[index])
		row.append(freeNumberPerDistrict[index])
		row.append(studentPermil[index])
		file_writer.writerow(row)
	pass
	csv_file.close()
pass
